<template>
  <div class="searchQuotes">
    <x-header :left-options="{backText: ''}"></x-header>
    <div class="searchText">
      <div class="searchIcon">
        <x-icon type="ios-search" size="25"></x-icon>
      </div>
      <input type="text" placeholder="搜索币种" v-model="searchText">
      <img src="../../assets/delate.png" alt="" width="15" height="15" class="delateIcon" @click="searchText=''">
    </div>
    <div class="searchHot">
      <div style="color:#666;margin-left:15px;font-size: 15px;" v-if="hotTag.length>0">
        热门搜索
      </div>
      <div class="searchRes">
        <span @click="searchCurr(tag.value)" v-for="tag in hotTag">{{tag.value}}</span>
      </div>
    </div>
    <div class="addCurrencyType">
      <ul>
        <li v-for="curr in currList">
          <span>{{curr.currencyPair}}</span>
          <div class="spanSty">
            <span @click="addCurrency(curr)">添加自选</span>
          </div>
        </li>
      </ul>
    </div>
  </div>
</template>
<script>
  import axios from 'axios'
  import { XHeader, Radio, Group } from 'vux'
  import http from '../../service/http.js'
  import tips from '../../service/tips.js'
  export default {
    data() {
      return {
        searchText: "",
        currList: [],
        hotTag:[],
      }
    },
    watch: {
      searchText(newValue, oldValue) {
        axios.get("http://47.52.241.237:8088/marketData/marketValues?currencyPair=" + newValue).then((res) => {
          if (res.data.success) {
            this.currList = res.data.data;
          }
        })
      }
    },
    mounted(){
       this.getHotTags();
    },
    methods: {
      // 热门搜索
      getHotTags(){
        axios.get("http://47.52.241.237:8088/marketData/tags").then((res)=>{
          if(res.status==200){
            this.hotTag=res.data.data;
          }
        })
      },
      searchCurr(text) {
        this.searchText=text;
        axios.get("http://47.52.241.237:8088/marketData/marketValues?currencyPair=" + text).then((res) => {
          if (res.data.success) {
            this.currList = res.data.data;
          }
        })
      },
      addCurrency(curr) {
        http.put("/market/choose", {
          exchangeName:curr.exchangeName,
          currencyPair:curr.currencyPair
        }).then((res) => {
          if (res.data.status == 200) {
            tips.tips("添加成功");
          }else{
            tips.tips(res.data.msg)
          }
        }).catch((res) => {
          tips.tisp(res.data.msg)
        })
      }

    },
    components: {
      XHeader,
      Group,
      Radio
    }
  }
</script>
<style lang="less">
  body {
    background: #f6f6f6;
  }

  .searchQuotes .vux-header {
    background: #fff;
  }

  .searchQuotes .vux-header .vux-header-title {
    line-height: 40px;
    text-align: center;
    font-size: 18px;
    font-weight: 400;
    color: #000;
  }

  .searchQuotes .vux-header .vux-header-left .left-arrow:before {
    content: "";
    position: absolute;
    width: 12px;
    height: 12px;
    border: 1px solid #000;
    border-width: 1px 0 0 1px;
    -webkit-transform: rotate(315deg);
    transform: rotate(315deg);
    top: 8px;
    left: 7px;
  }

  .searchQuotes .searchHot {
    background: #fff;
    padding-top: 8px;
    border-top: 1px solid #f6f6f6;
  }

  .searchQuotes .searchRes {
    padding-left: 6px;
    margin-top: 12px;
  }

  .searchQuotes .searchRes span {
    width: 60px;
    height: 25px;
    text-align: center;
    line-height: 25px;
    display: inline-block;
    border: 1px solid #f6f6f6;
    border-radius: 5px;
    background: #f6f6f6;
    margin-bottom: 12px;
    margin-right: 8px;
    color: #666;
    font-size: 13px;
  }

  .searchQuotes .delateIcon {
    position: absolute;
    right: 15px;
    top: 7px;
  }

  .searchQuotes .searchText {
    width: 75%;
    height: 30px;
    border: 1px solid #f6f6f6;
    border-radius: 25px;
    position: absolute;
    top: 8px;
    left: 50px;
    background: #f6f6f6;
    overflow: hidden;
    .searchIcon {
      position: absolute;
      left: 10px;
      top: 5px;
    }
    input {
      border: none;
      border-style: none;
      outline: none;
      background: #f6f6f6;
      margin-left: 40px;
      width: 70%;
      margin-top: 8px;
    }
  }

  .searchQuotes .weui-cells_radio .weui-check:checked+.weui-icon-checked:before {
    display: block;
    content: '\EA08';
    color: #FF9960;
    font-size: 16px;
  }

  .searchQuotes .addCurrencyType {
    border-top: 1px solid #f6f6f6;
  }

  .searchQuotes .addCurrencyType li {
    height: 55px;
    color: #333;
    line-height: 55px;
    background: #fff;
    border-bottom: 1px solid #f6f6f6;
    padding-left: 15px;
    position: relative;
  }

  .searchQuotes .spanSty {
    position: absolute;
    right: 15px;
    color: #fea620;
    top: 0px;
    span {
      width: 80px;
      height: 20px;
      border: 1px solid #fea620;
      padding: 1px 13px;
      border-radius: 5px;
      font-size: 13px;
    }
  }
</style>